package com.smart.chapter1;

import com.smart.chapter1.entity.MyBean;
import com.smart.chapter1.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Optional;

/**
 * @author cxy
 * @description jdk8 optional 空指针终结者
 * @date 2019年08月19 22:32:42
 */
public class OptionalSupport {

    private Optional<MyBean> myBean;

    @Autowired
    private void setMyBean(MyBean myBean) {
        this.myBean = Optional.of(myBean);
    }

    public User findUserByUserName(String userName) {
        if (myBean.isPresent()) {
            System.out.println(userName);
        }
        return new User();
    }

    @GetMapping("/user")
    public User getUser(@RequestParam("id") String id,@RequestParam("userName") Optional<String> userName) {
        return null;
    }
}
